<template>
    <el-container>
        <el-container class="is-vertical">
            <div class="panel-search-box">
                <div class="panel-search">
                    <el-input v-model="search.userName" placeholder="学员姓名" clearable  class="w165"></el-input>
                    <el-input v-model="search.teacherName" placeholder="教练姓名" clearable  class="w165"></el-input>
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                </div>
            </div>
            <el-main class="nopadding">
                <scTable ref="table" :apiObj="$API.vocabularyExam.list" remoteSort @dataChange="dataChange">
                    <el-table-column label="序号" prop="index" width="70" align="left"></el-table-column>
                    <el-table-column label="账号" prop="account" align="center">
                        <template #default="scope">
                            <template v-if="scope.row.user">
                                {{scope.row.user ? scope.row.user.account : ''}}
                            </template>
                            <template v-else-if="scope.row.teacher">
                                {{scope.row.teacher ? scope.row.teacher.account : ''}}
                            </template>
                        </template>
                    </el-table-column>
                    <el-table-column label="姓名" prop="name" align="center" width="120">
                        <template #default="scope">
                            <template v-if="scope.row.user">
                                {{scope.row.user ? scope.row.user.name : ''}}
                            </template>
                            <template v-else-if="scope.row.teacher">
                                {{scope.row.teacher ? scope.row.teacher.name : ''}}
                            </template>
                        </template>
                    </el-table-column>
                    <el-table-column label="正确" prop="rightNumber" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="错误" prop="wrongNumber" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="等级" prop="level" width="120" align="center">
                        <template #default="scope">
                            {{scope.row.rule ? scope.row.rule.level : ''}}
                        </template>
                    </el-table-column>
                    <el-table-column label="词汇量" prop="words" width="120" align="center">
                    </el-table-column>
                    <el-table-column label="测试时间" prop="createdAt" width="150" align="center"></el-table-column>
                    <el-table-column label="操作" fixed="right" align="center" width="220">
                        <template #default="scope">
                            <el-button type="text" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
                        </template>
                    </el-table-column>
                </scTable>
            </el-main>
        </el-container>
    </el-container>


    <detail-dialog v-if="dialog.detail" ref="detailDialog" @closed="dialog.detail=false"></detail-dialog>

</template>

<script>
import detailDialog from './detail'
export default {
    components: {
        detailDialog
    },
    data() {
        return {
            dialog: {
                detail: false,
            },
            search: {
                name: null,
            },
        }
    },
    mounted() {
        
    },
    methods: {
        dataChange(res, tableData) {
			let total = res.data.total
            let perPage = res.data.perPage
            let page = (this.$refs.table && this.$refs.table.currentPage) || 1
            tableData.forEach((item, index) => {
				item.index = page * perPage + index - perPage + 1
            })
        },
        //查看
        table_show(row) {
            this.dialog.detail = true
			this.$nextTick(() => {
				this.$refs.detailDialog.open(row.id)
			})
        },
        // 搜索
        upsearch() {
            this.$refs.table.upData(this.search)
        },
        //本地更新数据
        handleSuccess() {
            this.$refs.table.refresh()
        }
    }
}
</script>

<style>
.position {
    display: flex;
    align-items: center;
}
.position-item {
    margin-right: 5px;
}
.position-item:last-child {
    margin-right: 0;
}
</style>
